import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
/**
 * 通用权限校验组件
 * @author: ljq
 * @since: 2019-01-12 15:46:51
 */
import * as React from 'react';

var AuthCheck = function (_React$Component) {
    _inherits(AuthCheck, _React$Component);

    function AuthCheck() {
        _classCallCheck(this, AuthCheck);

        return _possibleConstructorReturn(this, (AuthCheck.__proto__ || Object.getPrototypeOf(AuthCheck)).apply(this, arguments));
    }

    _createClass(AuthCheck, [{
        key: 'render',
        value: function render() {
            var _props = this.props,
                children = _props.children,
                check = _props.check,
                storagetype = _props.storagetype;

            if (check) {
                var noAuth = false;
                if (storagetype && storagetype === "localStorage") {
                    if (!localStorage.allAuths) {
                        noAuth = true;
                    } else {
                        var allAuths = JSON.parse(localStorage.allAuths);
                        noAuth = !check.split(',').every(function (url) {
                            return allAuths.indexOf(url) > -1;
                        });
                    }
                    if (noAuth) {
                        return '';
                    }
                } else {
                    if (!sessionStorage.allAuths) {
                        noAuth = true;
                    } else {
                        var _allAuths = JSON.parse(sessionStorage.allAuths);
                        noAuth = !check.split(',').every(function (url) {
                            return _allAuths.indexOf(url) > -1;
                        });
                    }
                    if (noAuth) {
                        return '';
                    }
                }
            }
            return children;
        }
    }]);

    return AuthCheck;
}(React.Component);

export default AuthCheck;